<?php
/**
 * Created by JetBrains PhpStorm.
 * User: shaoshuai
 * Date: 11-10-2
 * Time: PM7:35
 * To change this template use File | Settings | File Templates.
 */

include_once '../paperblog.php';

$error = '';
$url = trim($_POST['url']);

$tags = array();
if (trim($_POST['tags']) !== '') {
    $tags = explode(',', $_POST['tags']);
    foreach ($tags as $key => $value) {
        $tags[$key] = trim($value);
    }
}

$post = array(
    'url' => $url,
    'title' => trim($_POST['title']),
    'content' => trim($_POST['content']),
    'category' => intval($_POST['category']), //category id
    'time' => time(), //int
    'tag' => $tags,
    'comments' => array(),
);
if (!addPost($post)) {
    $error = 'addpostfail';
}
addPostToCategory($url, $post['category']);
updateTags($url, $tags);
compilePostById($url, $post);
compileIndex();

header('Location: ' . SITE_URL . '/admin/add.php?error=' . $error);
